|
|
|
|
|
|
|
Note Remember that the Open and Save As dialog boxes don't actually perform any function; they simply get the information from users. It's up to your application code to perform the necessary commands to complete the task. |
|
|
|
|
|
|
|
|
|
To see how the Open and Save As dialog boxes can be used, you create a more robust version of the file copy project that you created on Day 1. This newer version will do the following: |
|
|
|
|
|
|
|
|
Allow users to pick a file |
|
|
|
|
|
|
|
|
Select whether to copy it or move it |
|
|
|
|
|
|
|
|
Specify the destination filename and path |
|
|
|
|
|
|
|
|
Check whether the file is being overwritten and warn users if it is |
|
|
|
|
|
|
|
|
When you work with any of the Common Dialog control's different functions, you use several properties to set up the interface. In the case of the Open/Save As dialog boxes, these properties are as follows: |
|
|
|
|
|
|
|
|
Filter, which sets the file-extension filters displayed in the Type list box |
|
|
|
|
|
|
|
|
FilterIndex, which contains the default filter for the Open and Save As dialog boxes |
|
|
|
|
|
|
|
|
Flags, which sets the options for the dialog boxes |
|
|
|
|
|
|
|
|
Filename, which contains the path and filename of a selected file |
|
|
|
|
|
|
|
|
DefaultExt, which is used as the extension when a file with no extension is saved |
|
|
|
|
|
|
|
|
InitDir, which sets the initial file directory that's displayed |
|
|
|
|
|
|
|
|
MaxFileSize, which indicates the maximum string size of the data in the Filename property |
|
|
|
|
|
|
|
|
The only two properties that require more than one or two lines to explain are Filter and Flags. The Filter property provides users with a list of filters to choose from. The pipe (¦) is used to separate the description and the filter values from each other. The following is an example of the syntax for setting the Filter property: |
|
|
|
|
|
|
|
|
Text (*.txt)¦*.txt¦Word Documents (*.doc)¦¦*.doc¦Any Files¦*.* |
|
|
|
|
|
|
|
|
Note Don't use any spaces before or after the pipe symbol. Any spaces would be displayed with the description and filter values. |
|
|
|
|
|
|